package cn.gailvlun.gll.presentation.charge.adapter

import android.content.Context
import cn.gailvlun.gll.R
import cn.gailvlun.gll.presentation.charge.model.ProductModel
import com.github.markzhai.recyclerview.SingleTypeAdapter

class ChargeAdapter: SingleTypeAdapter<ProductModel> {
    constructor(context: Context?) : super(context, R.layout.item_charge)

    public fun getData(): List<ProductModel> {
        return mCollection
    }

    public fun selectProduct(index: Int) {
        getCurrentProduct()?.isSelected = false
        mCollection[index].isSelected = true
        notifyDataSetChanged()
    }

    public fun getCurrentProduct(): ProductModel? {
        for (productModel in mCollection) {
            if (productModel.isSelected) {
                return productModel
            }
        }
        return null
    }
}